import { Controller } from "../../mvc/core/Controller";
import { INoviceCardController } from "./interfaces/INoviceCardController";
import { IView } from "../../mvc/interfaces/IView";
import { NoviceCardModule } from "../../../modules/NoviceCardModule";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { INoviceCardModule } from "../../../modules/interfaces/INoviceCardModule";
import { ParamsConst } from "../../common/global/ParamsConst";
import { PromotionCardConfig } from "../resource/PromotionCardConfig";
import { GameProxy } from "../mvc/GameProxy";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
type int = number;
//class NoviceCardController
    
    export  class NoviceCardController extends Controller implements INoviceCardController
    {
       

        protected /* override */ initView(): IView
        {
            if (this._noviceCard == null) 
            {
                this._noviceCard = new NoviceCardModule();
            }
            return this._noviceCard;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.NoviceCardOpen, this.onNoviceCardOpenHandler);
            Dispatcher.addEventListener(EventName.NovicePackGet, this.onNovicePackGetHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUse, this.onNoviceCardUseHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUseSuccess, this.onNoviceCardUseSuccessHandler);
            Dispatcher.addEventListener(EventName.NoviceCardUseFail, this.onNoviceCardUseFailHandler);
            return;
        }

        /* internal  */onNoviceCardOpenHandler(arg1: DataEvent): void
        {
            if (view == null) 
            {
                this.initView();
            }
            view.show();
            if (arg1.data) 
            {
                (view as INoviceCardModule).updateUrl(arg1.data as string);
            }
            else 
            {
                (view as INoviceCardModule).updateUrl(ParamsConst.instance.xskUrl);
            }
            return;
        }

        /* internal  */onNovicePackGetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            var loc2="000000000000";
            this._cardName = PromotionCardConfig.instance.getCardNameByType(loc1);
            GameProxy.noviceCardProxy.useNoviceCard(loc1, loc2);
            return;
        }

        /* internal  */onNoviceCardUseHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Object;
            this._cardType = loc1.type;
            this._cardName = PromotionCardConfig.instance.getCardNameByType(this._cardType);
            GameProxy.noviceCardProxy.useNoviceCard(this._cardType, loc1.key);
            return;
        }

        /* internal  */onNoviceCardUseSuccessHandler(arg1: DataEvent): void
        {
            view.hide();
            MsgManager.showRollTipsMsg(Language.getString(35803) + this._cardName);
            return;
        }

        /* internal  */onNoviceCardUseFailHandler(arg1: DataEvent): void
        {
            if (this._noviceCard != null) 
            {
                this._noviceCard.resetModule();
            }
            var loc1=arg1.data as int;
            var loc2="";
            if (loc1 != 35600) 
            {
                if (loc1 != 35601) 
                {
                    if (loc1 != 35602) 
                    {
                        if (loc1 != 35603) 
                        {
                            if (loc1 != 35340) 
                            {
                                MsgManager.showErrorByCode(loc1, loc1.toString());
                            }
                            else 
                            {
                                loc2 = Language.getString(35810);
                            }
                        }
                        else 
                        {
                            loc2 = Language.getStringByParam(35809, this._cardName);
                        }
                    }
                    else 
                    {
                        loc2 = Language.getStringByParam(35808, this._cardName);
                    }
                }
                else if (this._cardName != Language.getString(35805)) 
                {
                    loc2 = Language.getStringByParam(35807, this._cardName);
                }
                else 
                {
                    loc2 = Language.getString(35806);
                }
            }
            else 
            {
                loc2 = Language.getStringByParam(35804, this._cardName);
            }
            if (loc2 != "") 
            {
                MsgManager.showRollTipsMsg(loc2);
            }
            return;
        }

        private /* var */_noviceCard: INoviceCardModule;

        private /* var */_cardType: int;

        private /* var */_cardName: string;
    }
